package com.oba.king.datalib;

import java.util.Date;

import com.oba.base.dao.DBDataModel;
import com.oba.base.service.BaseBean;

/**
 * 
 * @author 大饼
 * 公司信息及公司账户信息管理
 */

public class CompanyInfoBean extends BaseBean<CompanyInfo, CompanyInfoService> {

	private DBDataModel companyinfoData = DBDataModel.create();
	private CompanyInfo companyInfo;
	
	private boolean showCompanyInfo;
	
	//查询 条件
	private CompanyCondition companyCondition;
	//是否弹出账号详细信息弹出层
	private boolean showAccountInfo;
	
	public void doAddRow() {
		companyInfo = new CompanyInfo();
		companyInfo.setNewBo(true);
		AccountValues av = new AccountValues();
		av.setLastUpdateDate(new Date());
		av.setNewBo(true);
		companyInfo.setAccountValue(av);
		showCompanyInfo = true;
	}
	
	public void doEditRow() {
		if(companyinfoData.isRowAvailable()) {
			companyInfo = (CompanyInfo) companyinfoData.getRowData();
			showCompanyInfo = true;
			doFind();
		}
	}
	//显示账号详细信息
	public void showAccoutDetails(){
		
		if(companyinfoData.isRowAvailable()) {
			companyInfo = (CompanyInfo) companyinfoData.getRowData();
			showAccountInfo = true;
		}
	}
	//关闭账号详细信息
	public void closeShowAccount() {
		showAccountInfo = false;
	}
	
	public void clearCompanyCondition(){
		companyCondition=new CompanyCondition();
	}
	
	public void doDeleteRow() {
		if(companyinfoData.isRowAvailable()) {
			companyInfo = (CompanyInfo) companyinfoData.getRowData();
			getService().del(companyInfo);
			doFind();
		}
	}
	
	public void closeShowEdit() {
		showCompanyInfo = false;
	}
	
	public void doSaveRow() {
		// TODO
		getService().save(companyInfo.getAccountValue());
		getService().save(companyInfo);
		showCompanyInfo = false;
		doFind();
	}

	@Override
	public String doFind() {
		companyinfoData.find(getService().getDao().findAll());
		return null;
	}
	
	public void findByCompany(){
		companyinfoData.find(getService().getDao().findByCompany(companyCondition));
	}

	@Override
	public void init() {
		//companyinfoData =DBDataModel.create(); 
		companyinfoData.find(getService().getDao().findAll());
		companyInfo = new CompanyInfo();
		companyCondition=new CompanyCondition();
		showCompanyInfo = false;
	}

	public DBDataModel getCompanyinfoData() {
		return companyinfoData;
	}

	public void setCompanyinfoData(DBDataModel companyinfoData) {
		this.companyinfoData = companyinfoData;
	}

	public CompanyInfo getCompanyInfo() {
		return companyInfo;
	}

	public void setCompanyInfo(CompanyInfo companyInfo) {
		this.companyInfo = companyInfo;
	}

	public boolean isShowCompanyInfo() {
		return showCompanyInfo;
	}

	public void setShowCompanyInfo(boolean showCompanyInfo) {
		this.showCompanyInfo = showCompanyInfo;
	}

	public CompanyCondition getCompanyCondition() {
		return companyCondition;
	}

	public void setCompanyCondition(CompanyCondition companyCondition) {
		this.companyCondition = companyCondition;
	}
	public boolean isShowAccountInfo() {
		return showAccountInfo;
	}

	public void setShowAccountInfo(boolean showAccountInfo) {
		this.showAccountInfo = showAccountInfo;
	}

}
